/*
package com.xw.service.tool.aws;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.*;
import com.google.common.collect.Maps;
import com.xw.common.Const;
import com.xw.util.PropertiesUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class AmazonawsServiceImpl implements AmazonawsService {

    private static final String accessKey = PropertiesUtil.getProperty("AWS_KEY");
    private static final String secretKey = PropertiesUtil.getProperty("AWS_SECRET");
    private static final String bucket = PropertiesUtil.getProperty("AWS_BUCKET");

    */
/**
     * 获取 AmazonS3 连接对象
     * @return
     *//*

    private static AmazonS3 getAmazonS3(){
        //创建Amazon S3对象
        AWSCredentials credentials;
        AmazonS3 s3Client;
        credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3Client = new AmazonS3Client(credentials);
//        设置区域  AP_SOUTHEAST_2 - 亚太悉尼
        Region cnnorth1 = Region.getRegion(Regions.AP_SOUTHEAST_2);
        s3Client.setRegion(cnnorth1);
        return s3Client;
    }


    */
/**
     * 查看所有可用的bucket
     *//*

    public Map getAllBucket(){
        Map map = Maps.newHashMap();
        AmazonS3 s3Client = getAmazonS3();
        List<Bucket> buckets = s3Client.listBuckets();
        for (Bucket bucket : buckets) {
            System.out.println("Bucket: " + bucket.getName());
        }
        map.put("buckets",buckets);
        return map;
    }

    */
/**
     * 查看bucket下所有的object
     *//*

    public static void getAllBucketObject(){
        AmazonS3 s3Client = getAmazonS3();
        ObjectListing objects = s3Client.listObjects(bucket);
        do {
            for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
                System.out.println("Object: " + objectSummary.getKey());
            }
            objects = s3Client.listNextBatchOfObjects(objects);
        } while (objects.isTruncated());
    }

    */
/**
     * amazonS3文件上传
     * @param bucketName 保存到某个存储桶
     * @param key 保存文件的key （以key-value形式保存）
     * @param file 上传文件
     *//*

    public Map amazonS3Upload(String bucketName,String key,File file){
        Map map = Maps.newHashMap();
        AmazonS3 s3Client = getAmazonS3();
        PutObjectResult result=s3Client.putObject(new PutObjectRequest(bucketName, key, file));
        System.out.println("PutObjectResult: "+result.toString());
        map.put("result",result);
        return map;
    }

    */
/**
     * amazonS3文件下载
     * @param bucketName 下载某个存储桶的数据
     * @param key 下载文件的key
     * @param targetFilePath 下载文件保存地址
     *//*

    public void amazonS3Downloading(String bucketName,String key,String targetFilePath){
        AmazonS3 s3Client = getAmazonS3();
        S3Object object = s3Client.getObject(new GetObjectRequest(bucketName,key));
        if(object!=null){
            System.out.println("Content-Type: " + object.getObjectMetadata().getContentType());
            InputStream input = null;
            FileOutputStream fileOutputStream = null;
            byte[] data = null;
            try {
                //获取文件流
                input=object.getObjectContent();
                data = new byte[input.available()];
                int len = 0;
                fileOutputStream = new FileOutputStream(targetFilePath);
                while ((len = input.read(data)) != -1) {
                    fileOutputStream.write(data, 0, len);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }finally{
                if(fileOutputStream!=null){
                    try {
                        fileOutputStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if(input!=null){
                    try {
                        input.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    */
/**
     * 文件删除
     * @param bucketName 删除文件所在存储桶
     * @param key 删除文件key
     *//*

    public Map amazonS3DeleteObject(String bucketName,String key){
        Map map = Maps.newHashMap();
        AmazonS3 s3Client = getAmazonS3();
        s3Client.deleteObject(bucketName, key);
        map.put("code", Const.SUCCESS_CODE);
        return map;
    }

    */
/**
     * 删除存储桶
     * @param bucketName 需要删除的存储桶
     *//*

    public Map amazonS3DeleteBucket(String bucketName){
        Map map = Maps.newHashMap();
        AmazonS3 s3Client = getAmazonS3();
        s3Client.deleteBucket(bucketName);
        map.put("code", Const.SUCCESS_CODE);
        return map;
    }

}
*/
